import request from "@/service/request";
import { PromisePageResponse, PromiseResponse } from "@/service/api/type.ts";
import {
  ClientUserInfoVo,
  ClientUserVo,
  OrganizationNode,
  RegionNode,
} from "@/service/api/system/frontUser/types.ts";

/**
 * 获取客户端用户列表
 * @param query
 */
const getClientUserList = (query: any): PromisePageResponse<ClientUserVo> => {
  return request({
    url: "/client/user/list",
    method: "get",
    params: query,
  });
};

/**
 * 新增客户端用户
 * @param query
 */
const createClientUser = (query: any): PromiseResponse<any> => {
  return request({
    url: "/client/user",
    method: "post",
    data: query,
  });
};

/**
 * 查询详情
 * @param id
 */
const getClientUserDetail = (id: string): PromiseResponse<ClientUserInfoVo> => {
  return request({
    url: `/client/user/getInfoByBack/${id}`,
    method: "get",
  });
};

/**
 * 修改详情
 * @param query
 */
const updateClientUser = (query: any): PromiseResponse<any> => {
  return request({
    url: "/client/user/edit",
    method: "put",
    data: query,
  });
};

/**
 * 删除测用户
 * @param id
 */
const deleteClientUser = (id: string | Array<string>): PromiseResponse<any> => {
  return request({
    url: `/client/user/${id}`,
    method: "delete",
  });
};

/**
 * 获取区域树
 */
const getDefaultRegionTree = (): PromiseResponse<RegionNode> => {
  return request({
    url: "/region/treeselect",
    method: "get",
  });
};

/**
 * 获取组织树
 * @param query
 */
const getOrganization = (query?: any): PromiseResponse<OrganizationNode> => {
  return request({
    url: "/system/organization/treeselect",
    method: "get",
    params: query,
  });
};

/**
 * 上传excel
 * @param formData
 */
const importExcel = (formData: any): PromiseResponse<any> => {
  return request({
    url: "/client/user/importData",
    method: "post",
    data: formData,
  });
};

// 获取用户评价
const getEvaluateList = (query: any) => {
  return request({
    url: `/course/review/page`,
    method: "get",
    params: query,
  });
};

// /**
//  * 获取导入模板
//  */
// const getExportTemplate = () => {
//   return request({
//     url: "/client/user/importTemplate",
//     method: "post",
//   });
// };

// 获取用户评论
const getCommentList = (query: any) => {
  return request({
    url: `/client/comment/list`,
    method: "get",
    params: query,
  });
};
// 获取用户日记
const getDiaryList = (query: any) => {
  return request({
    url: `/course/diary/list`,
    method: "get",
    params: query,
  });
};
// 获取用户笔记
const getNotesList = (query: any) => {
  return request({
    url: `/course/note/list`,
    method: "get",
    params: query,
  });
};

// 发送警告
const handleWarning = (id: string, msg: string) => {
  return request({
    url: `/client/user/warning/` + id,
    method: "post",
    data: msg,
  });
};

// 重置家长名称
const resetName = (id: string) => {
  return request({
    url: `/client/user/resetNickname/` + id,
    method: "put",
  });
};

// 重置孩子名称
const resetChildName = (id: string) => {
  return request({
    url: `/course/child/resetNickname/` + id,
    method: "put",
  });
};

// 禁言
const ban = (query: any) => {
  return request({
    url: "/client/user/mute",
    method: "post",
    data: query,
  });
};

// 解除禁言
const cancelBan = (id: string) => {
  return request({
    url: "/client/user/cancelMute/" + id,
    method: "post",
  });
};

// 移出小孩
const removeChild = (id: string) => {
  return request({
    url: "/course/child/removeClass/" + id,
    method: "post",
  });
};
/**
 * 获取组织树
 * @param query
 */
const getOrganizationTree = (
  query: any,
): PromisePageResponse<OrganizationNode> => {
  return request({
    url: "/system/organization/treeselect",
    method: "get",
    params: query,
  });
};

// 隐藏按钮
const handleHide = (id: string) => {
  return request({
    url: `/client/dynamic/forbidden/${id}`,
    method: "post",
  });
};

// 隐藏评论按钮
const handleCommentHide = (status: string, id: string) => {
  return request({
    url: `/client/comment/changeStatus`,
    method: "put",
    data: {
      status,
      id,
    },
  });
};

// 删除评价
const deleteEvaluate = (id: string) => {
  return request({
    url: `/course/review/remove`,
    method: "delete",
    params: {
      id,
    },
  });
};

// 删除评论
const deleteComment = (id: string) => {
  return request({
    url: `/client/comment/${id}`,
    method: "delete",
  });
};

// 删除日记
const deleteDiary = (id: string) => {
  return request({
    url: `/course/diary/${id}`,
    method: "delete",
  });
};

// 删除笔记
const deleteNotes = (id: string) => {
  return request({
    url: `/course/note/${id}`,
    method: "delete",
  });
};

export {
  getClientUserList,
  createClientUser,
  getClientUserDetail,
  updateClientUser,
  deleteClientUser,
  getDefaultRegionTree,
  getOrganization,
  importExcel,
  getEvaluateList,
  getCommentList,
  getDiaryList,
  getNotesList,
  handleWarning,
  resetName,
  resetChildName,
  ban,
  cancelBan,
  removeChild,
  getOrganizationTree,
  handleHide,
  handleCommentHide,
  deleteEvaluate,
  deleteComment,
  deleteDiary,
  deleteNotes,
};
